package pl.un4giv3n.mightvsmagic.admin.action;

import java.util.Date;

import javax.persistence.EntityManager;

import pl.un4giv3n.mightvsmagic.action.PersistenceAction;
import pl.un4giv3n.mightvsmagic.entity.User;
import pl.un4giv3n.mightvsmagic.entity.UserType;

public class SetPremiumBonusAction extends PersistenceAction{

	private static final long serialVersionUID = 1L;
	private Date premiumBonusEnd;
	
	@Override
	public String execute() {
		EntityManager em = getEntityManager();
		User user = getSessionUser(em);
		em.close();
		if (user == null || user.getUserType() != UserType.ADMIN) {
			addActionError("Zaloguj się");
			return LOGIN;
		}
		PremiumBonusHolder.setPremiumEndDate(premiumBonusEnd);
		return super.execute();
	}

	public Date getPremiumBonusEnd() {
		return premiumBonusEnd;
	}

	public void setPremiumBonusEnd(Date premiumBonusEnd) {
		this.premiumBonusEnd = premiumBonusEnd;
	}
}
